

<!--编辑或添加商户信息-->
<div id='Store_Main_SubArea' >
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;text-align:right'>商户名称：</div>
		<div style='flex:1'><input id='StoreEdit_Name' style='width:90%' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>联系电话：</div>
		<div style='flex:1'><input id='StoreEdit_Phone' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;text-align:right'>Q Q：</div>
		<div style='flex:1'><input id='StoreEdit_Qq' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>微信：</div>
		<div style='flex:1'><input id='StoreEdit_Wx' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>商户地址：</div>
		<div style='flex:1'><input id='StoreEdit_Addr' style='width:90%' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>商户描述：</div>
		<div style='flex:1'><textarea id="StoreEdit_Info" style='width:90%;height:150px;resize:none' ></textarea></div>
	</div>


	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;text-align:right'>店铺封面：</div>
		<div style='flex:1'>
			<input type="file" id='StoreEdit_File'  />
		</div>
	</div>
	
	<div style='text-align:center;margin:20px auto'>
		<button id='StoreEdit_SubBtn'>提交</button>
		<button id='StoreEdit_BackBtn'>返回</button>
	</div>

	<div style='font-size:12px;color:red;text-align:center'>
		注：每年只能修改三次(当前已用<span id='StoreEditCount'></span>次)
	</div>
</div>



<script>


	var StoreEdit_AddFile;	//添加时封面图的临时变量
	var EditFile;	//编辑时封面图的临时变量

	//返回按钮
	$('#StoreEdit_BackBtn').click(function(){
		$('#StoreViewArea').show();
		$('#StoreMain_StoreEdit').hide();
	});

	//显示修改次数
	$('#StoreEditCount').text(accountInfo.change_count);

	//添加或编辑商户信息提交
	$('#StoreEdit_SubBtn').click(function(){
	//	C(StoreInfo);
		var StoreEdit_Name = ChangeChar($('#StoreEdit_Name').val().trim());
		Field_Check(/^.{3,20}$/,StoreEdit_Name,'js商户名长度为3-20个字符!');

		var StoreEdit_Phone = ChangeChar($('#StoreEdit_Phone').val().trim());
		Field_Check(/^[1-9][0-9]{6,11}$/,StoreEdit_Phone,'js电话格式不正确!');
	
		var StoreEdit_Qq = ChangeChar($('#StoreEdit_Qq').val().trim());
		Field_Check(/^[1-9][0-9]{4,11}$|^$/,StoreEdit_Qq,'jsQQ号不正确!');

		var StoreEdit_Wx = ChangeChar($('#StoreEdit_Wx').val().trim());
		Field_Check(/^[a-zA-z0-9_-]{3,30}$|^$/,StoreEdit_Wx,'js微信号格式不正确!');

		var StoreEdit_Addr = ChangeChar($('#StoreEdit_Addr').val().trim());
		Field_Check(/^.{1,50}$|^$/,StoreEdit_Addr,'js地址长度不超过50个字符!');

		var StoreEdit_Info = ChangeChar($('#StoreEdit_Info').val().trim());
		Field_Check(/^.{1,300}$/,StoreEdit_Info,'js商户描述不得为空且不得超过300字符!');


	

		//Notice('处理中......');
		var formData = new FormData();
		if(StoreEdit_AddFile){
			formData.append('banner',StoreEdit_AddFile); //添加文件
		}
		formData.append('name',StoreEdit_Name); 
		formData.append('phone',StoreEdit_Phone); 
		formData.append('qq',StoreEdit_Qq); 
		formData.append('wx',StoreEdit_Wx); 
		formData.append('addr',StoreEdit_Addr); 
		formData.append('info',StoreEdit_Info); 
		formData.append('type','StoreInfoEdit'); 
		formData.append('token1',sessionStorage.store_token1); 
		formData.append('user',accountInfo.account); 
		formData.append('db_host',cityInfo[1]); 
		formData.append('db_name',cityInfo[2]); 
		formData.append('cityCode',cityInfo[0]);

		AjaxFile(formData,function(res){
			C(res);
			var tmp = _checkJsonFormat(res,1); //检测JSON格式
			switch(tmp.stat){
				case 'ok':
					accountInfo.name = StoreEdit_Name;
					accountInfo.phone = StoreEdit_Phone;
					accountInfo.qq = StoreEdit_Qq;
					accountInfo.wx = StoreEdit_Wx;
					accountInfo.addr = StoreEdit_Addr;
					accountInfo.stat = 1;
					accountInfo.info = StoreEdit_Info;
					accountInfo.banner = /^\/banner.*$/.test(tmp.banner)?tmp.banner:accountInfo.banner;
					accountInfo.change_count = parseInt(accountInfo.change_count) + 1 ;
					sessionStorage.store_user_info = JSON.stringify(accountInfo);
					A('商户修改成功！');
					location.reload();
				break;
				case 'err2':A('修改次数已用尽！');break;
				case 'err3':A('文件上传失败！');break;
				case 'err4':A('操作异常！');break;
			}
		},requestAddr);
	});











	//选择图片并验证保存到变量中
	SelectOrViewImg('StoreEdit_File','StoreMain_Banner',function(file){
		if(file != 'err'){
			StoreEdit_AddFile = file;
		}else{
			A('文件类型不正确或大小超限!');
		}
	});	//限制大小500k


	StoreEdit_PasrseStoreInfo(accountInfo);	//解析并显示商户信息


	//解析并显示商户信息
	function StoreEdit_PasrseStoreInfo(res){
		if(typeof(res) != 'object' && res.length < 1){
			return;
		}
		var info = res;
		$('#StoreEdit_Name').val(ChangeChar(info.name,1));
		$('#StoreEdit_Phone').val(info.phone);
		$('#StoreEdit_Qq').val(info.qq);
		$('#StoreEdit_Wx').val(info.wx);
		$('#StoreEdit_Addr').val(ChangeChar(info.addr,1));
		$('#StoreEdit_Info').val(ChangeChar(info.info,1));
	}
</script>